<template>
  <div>
    <headerComponent></headerComponent>
    <div class="exam">
      <div style="width: 1200px;margin: 0 auto;padding-bottom: 100px">
        <el-card>
          <el-page-header @back="goBack" content=""></el-page-header>
        </el-card>
        <el-card>
          <userKnow @showExamAgreement="showExamAgreement"
                    v-if="isUserKnow_or_ExamAgreement_or_Exam === 'isUserKnow'"></userKnow>
          <ExamAgreement @isExam="isExam"
                         v-else-if="isUserKnow_or_ExamAgreement_or_Exam === 'ExamAgreement'"></ExamAgreement>
          <el-form
                  v-else-if="isUserKnow_or_ExamAgreement_or_Exam === 'Exam'"
                  label-position="top"
                  ref="examForm"
                  :rules="rules"
                  label-width="120px"
                  :model="examForm"
          >
            <!-- <el-steps align-center :active="active" finish-status="success">
              <el-step title="步骤 1"></el-step>
              <el-step title="步骤 2"></el-step>
              <el-step title="步骤 3"></el-step>
            </el-steps> -->
            <div style="padding: 20px; text-align: left">
              <!-- v-show="active == 1" -->
              <div>
                <!--                {{examForm}}-->
                <el-row :gutter="20">
                  <el-col :span="5">
                    <el-form-item :required="true" label="机构代码">
                      <el-input
                              size="small"
                              v-model="examForm.exam_org_code"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item :required="true" label="您报读的培训机构">
                      <el-input
                              size="small"
                              :disabled="true"
                              v-model="examForm.org.org_name"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="5">
                    <el-form-item :required="true" label="您报考的级别">
                      <el-input
                              size="small"
                              :disabled="true"
                              v-model="examForm.course.name"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item :required="true" label="考试形式">
                      <el-select
                              size="small"
                              style="width: 100%"
                              v-model="examForm.exam_city"
                              placeholder="请选择考试形式"
                      >
                        <el-option
                                v-for="item in examCityOptions"
                                :key="item.id"
                                :label="item.exam_city"
                                :value="item.exam_city"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item :required="true" label="考试时间">
                      <!--                    {{examDateOptions}}-->
                      <el-select
                              style="width: 100%"
                              size="small"
                              v-model="examForm.exam_date"
                              placeholder="请选择考试时间"
                      >
                        <el-option
                                v-for="item in examDateOptions"
                                :key="item.id"
                                :label="String(item.exam_date)"
                                :value="item.id"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="5">
                    <el-form-item prop="name" label="姓名">
                      <el-input
                              size="small"
                              :disabled="true"
                              v-model="examForm.name"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <!--                    {{examForm.exam_list.is_pass}}-->
                    <el-form-item :required="true" label="是否属于再次报考">
                      <el-tag type="primary" size="small">
                        {{
                        (examForm.exam_record.length > 0 &&
                        examForm.exam_record[examForm.exam_record.length - 1].is_pass === false)
                        || examForm.make_up_count > 0 ? '是' : '否'
                        }}
                      </el-tag>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row :gutter="20">
                  <el-col :span="5">
                    <el-form-item prop="last_py" label="姓拼音">
                      <el-input
                              onblur="this.value=this.value.toUpperCase()"
                              size="small"
                              v-model="examForm.last_py"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item prop="first_py" label="名拼音">
                      <el-input
                              onblur="this.value=this.value.toUpperCase()"
                              size="small"
                              v-model="examForm.first_py"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item :required="true" label="性别">
                      <el-radio-group
                              :disabled="true"
                              v-model="examForm.gender"
                      >
                        <el-radio :label="'m'">男</el-radio>
                        <el-radio :label="'f'">女</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="5">
                    <el-form-item :required="true" label="证件类型">
                      <el-select

                              size="small"
                              :disabled="true"
                              v-model="examForm.card_type"
                              placeholder="请选择证件类型"
                      >
                        <el-option
                                v-for="item in cardOptions"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item :required="true" label="证件号码">
                      <el-input

                              size="small"
                              :disabled="true"
                              v-model="examForm.card_id"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item :required="true" label="出生日期">
                      <el-date-picker
                              size="small"
                              :disabled="true"
                              format="yyyy 年 MM 月 dd 日"
                              value-format="yyyy-MM-dd"
                              placeholder="选择日期"
                              v-model="examForm.birthday"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">

                  <el-col :span="5">
                    <el-form-item prop="hig_edu" label="最高学历">
                      <el-select
                              style="width: 100%"
                              size="small"
                              :disabled="true"
                              v-model="examForm.hig_edu"
                              placeholder="最高学历"
                      >
                        <el-option
                                label="博士及以上"
                                value="博士及以上"
                        ></el-option>
                        <el-option label="研究生" value="研究生"></el-option>
                        <el-option label="本科" value="本科"></el-option>
                        <el-option label="专科" value="专科"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item prop="major" label="相关专业">
                      <el-select
                              style="width: 100%"
                              size="small"
                              :disabled="false"
                              v-model="examForm.major"
                              placeholder="相关专业"
                      >
                        <el-option label="人力资源管理" value="人力资源管理"></el-option>
                        <el-option label="工商管理" value="工商管理"></el-option>
                        <el-option label="行政管理" value="行政管理"></el-option>
                        <el-option label="会计" value="会计"></el-option>
                        <el-option label="财政、税务" value="财政、税务"></el-option>
                        <el-option label="财务管理" value="财务管理"></el-option>
                        <el-option label="其他" value="其他"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col v-if="examForm.grad_time" :span="5">
                    <el-form-item prop="grad_time" label="毕业年份">
                      <el-date-picker
                              size="small"
                              style="width: 100%"
                              type="month"
                              :clearable="false"
                              format="yyyy 年 MM 月"
                              value-format="yyyy-MM-dd"
                              placeholder="选择日期"
                              v-model="examForm.grad_time"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>

                </el-row>
                <el-row :gutter="80">
                  <el-col :span="6">
                    <el-form-item prop="com_name" label="单位名称">
                      <el-input
                              style="width:280px; margin-right: 20px"
                              size="small"
                              v-model="examForm.com_name"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="10">
                    <el-form-item prop="province" label="工作区域">
                      <el-cascader
                              style="width: 100%!important;"
                              size="small"
                              clear
                              :options="areaOptions"
                              v-model="selectedOptions"
                              @change="addressChangeExam"
                      >
                      </el-cascader>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="80">
                  <el-col :span="6">
                    <el-form-item prop="com_type" label="单位类型">
                      <el-select
                              style="width:280px; margin-right: 20px"
                              size="small"
                              v-model="examForm.com_type"
                              placeholder="请选择单位类型"
                      >
                        <el-option
                                v-for="item in com_typeList"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="10">
                    <el-form-item prop="work_duty" label="职务">
                      <el-select
                              style="width: 420px; margin-right: 20px"
                              size="small"
                              :disabled="true"
                              v-model="examForm.work_duty"
                              placeholder="请选择职务"
                      >
                        <el-option
                                v-for="item in work_dutyList"
                                :key="item.value"
                                :label="item.value.split('#')[0]"
                                :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="80">
                  <el-col :span="6">
                    <el-form-item prop="ind_type" label="行业类型">
                      <el-select
                              style="width:280px; margin-right: 20px"
                              size="small"
                              v-model="examForm.ind_type"
                              placeholder="请选择行业类型"
                      >
                        <el-option
                                v-for="item in ind_typeList"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="10">
                    <el-form-item prop="cert" label="相关资质或证书">
                      <el-select
                              size="small"
                              :disabled="true"
                              style="width: 420px; margin-right: 20px"
                              v-model="examForm.cert"
                              placeholder="请选择"
                      >
                        <el-option
                                v-for="item in certDisplayOptions"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row :gutter="80">
                  <el-col :span="6">
                    <el-form-item prop="email" label="电子邮箱">
                      <el-input
                              style="width:280px; margin-right: 20px"
                              size="small"
                              v-model="examForm.email"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="10">
                    <el-form-item prop="work_age" label-width="auto">
                      <span style="display: inline-block;font-size: 14px;color: #606266;line-height: 40px;"><span style="color: red">*</span>
                                            从事薪酬管理（含薪税服务）工作年限（含实习经历）
                                        <el-tooltip content="考生从事薪酬管理（含薪税服务）的工作年限（含实习经历）以首次培训报名所填写的年数为准" placement="top" effect="light">
                                          <el-tag style="cursor: pointer" size="mini">提示</el-tag>
                                        </el-tooltip>
                                        </span>
                      <el-input
                              :disabled="true"
                              size="small"
                              type="number"
                              v-model="examForm.work_age"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>

              </div>
              <!-- v-show="active == 2" -->
              <div>


              </div>
              <div>

                <el-row :gutter="80">
                  <el-col :span="6">
                    <el-form-item :required="true" prop="phone" label="手机号码">
                      <el-input
                              style="width:280px; margin-right: 20px"
                              size="small"
                              :disabled="true"
                              v-model="examForm.phone"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item prop="msg_code" label="短信验证码">
                      <div style="display: flex; align-items: center">
                        <el-input
                                size="small"
                                v-model="examForm.msg_code"
                        ></el-input>
                        <el-button
                                :disabled="isDisabled"
                                size="mini"
                                style="margin-left: 10px; height: 32px"
                                @click.stop="codeHandle"
                        >
                          <tencent-captcha
                                  ref="captcha"
                                  :phone="examForm.phone"
                                  scene="2"
                          ></tencent-captcha>
                        </el-button>
                      </div>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">

                </el-row>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item style="text-align: left;">
                      <el-checkbox v-model="examForm.is_train"
                      ><span style="font-size:12px;">您确认经培训达规定的参考学时数。</span></el-checkbox
                      >
                      <div
                              style="
                          display: flex;
                          align-items: center;
                          font-size: 10px;
                        "
                      >
                        <el-checkbox
                                style="margin-right: 10px;"
                                v-model="isRegister"
                        >
                          <!--                          <span-->
                          <!--                          style="font-size:12px;"-->
                          <!--                            >本人已阅读并同意<el-link-->
                          <!--                            style="font-size:12px;"-->
                          <!--                              type="warning"-->
                          <!--                              @click="isPrivacyFun"-->
                          <!--                              >《隐私政策》</el-link-->
                          <!--                            ><el-link style="font-size:12px;" type="warning" @click="isRegisterFun"-->
                          <!--                              >《用户注册协议》</el-link-->
                          <!--                            >，并承诺在申请国际薪税师报考时所提供的个人信息及材料均真实、合法、有效，否则将承担一切责任及后果（包括但不限于已取得证书的宣告作废）。-->
                          <!--                          </span>-->
                          <!--                                                    <span style="font-size:12px;">本人承诺在申请 {{ this.examForm.course.name }} 报考时所提供的个人信息及材料真实、合法、有效，否则将承担一切责任及后果（包括但不限于已取得证书的宣告作废）。</span>-->
                          <span style="font-size:12px;">本人承诺在申请国际薪税师报考时所提供的个人信息及材料真实、合法、有效，否则将承担一切责任及后果（包括但不限于已取得证书的宣告作废）。</span>
                        </el-checkbox
                        >
                      </div>
                      <el-button size="small" type="primary" style="margin-top: 12px"
                                 @click="examReg">提交
                      </el-button>
                      <!--                                            <el-switch-->
                      <!--                                                    v-model="examForm.is_train"-->
                      <!--                                                    active-color="#13ce66">-->
                      <!--                                            </el-switch>-->
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </div>
          </el-form>
        </el-card>
      </div>
    </div>
    <footerComponent></footerComponent>
  </div>
</template>

<script>
  import ExamAgreement from '@/components/ExamAgreement/index'
  import {return_url} from "@/assets/return_url";
  import userKnow from '@/components/userKnow/index'
  import headerComponent from '@/components/headerComponent'
  import footerComponent from '@/components/footerComponent'
  import {areaData, textToCode, codeToText} from "@/utils/JdAreaData/areaData";
  import TencentCaptcha from "@/components/TencentCaptcha/TencentCaptcha";
  import {exam_data_list, exam_reg, generate_contract, getOrg, profile, userExtSign} from "@/request/api";
  import {cert_list, work_duty_list} from "../../../assets/staticList";

  export default {
    name: "index",
    data() {
      var last_py_rule = (rule, value, callback) => {
        let reg = /^[A-Z,a-z]+$/;
        if (value === "") {
          callback(new Error("请填写姓拼音"));
        } else if (!reg.test(value)) {
          callback(new Error("格式错误"));
        } else {
          callback();
        }
      };
      var first_py_rule = (rule, value, callback) => {
        let reg = /^[A-Z,a-z]+$/;
        if (value === "") {
          callback(new Error("请填写名拼音"));
        } else if (!reg.test(value)) {
          callback(new Error("格式错误"));
        } else {
          callback();
        }
      };
      var province_rule = (rule, value, callback) => {
        console.log("工作区域验证函数", value);
        // console.log(_this.examForm.province);
        if (this.examForm.province === "" || this.examForm.province == null) {
          callback(new Error("请选择工作区域"));
        } else {
          callback();
        }
      };
      var work_duty_en_rule = (rule, value, callback) => {
        let reg = /^[A-Z,a-z]+$/;
        console.log("现有职务英文", value);
        if (value == null) {
          callback(new Error("请填写现有职务英文"));
        } else if (!reg.test(value)) {
          callback(new Error("格式错误"));
        } else {
          callback();
        }
      };
      var phoneRule = (rule, value, callback) => {
        let phoneRule = /^1[23456789]\d{9}$/;
        if (value === "") {
          callback(new Error("请输入手机号码"));
        } else if (!phoneRule.test(value)) {
          callback(new Error("手机号码格式错误"));
        } else {
          callback();
        }
      };
      var province_rule_update = (rule, value, callback) => {
        console.log("工作区域验证函数", value);
        console.log(_this.examForm.province);
        if (this.form.province === "" || this.form.province == null) {
          callback(new Error("请选择工作区域"));
        } else {
          callback();
        }
      };
      var email_rule = (rule, value, callback) => {
        let reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        if (value === "") {
          callback(new Error("请填写电子邮箱"));
        } else if (!reg.test(value)) {
          callback(new Error("电子邮箱格式错误"));
        } else {
          callback();
        }
      };
      var card_id_rule = (rule, value, callback) => {
        if (this.form.card_type == 1) {
          let reg =
                  /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
          if (value === "") {
            callback(new Error("请填写身份证号码"));
          } else if (!reg.test(value)) {
            callback(new Error("身份证格式错误"));
          } else {
            callback();
          }
        } else if (this.form.card_type == 2) {
          let reg = /^[A-Z,a-z,\d]+$/;
          if (value === "") {
            callback(new Error("请填写护照"));
          } else if (!reg.test(value)) {
            callback(new Error("护照格式错误"));
          } else {
            callback();
          }
        } else if (this.form.card_type == 3) {
          let reg = /^[A-Z,a-z,\d]+$/;
          if (value === "") {
            callback(new Error("请填写港澳台胞证"));
          } else if (!reg.test(value)) {
            callback(new Error("证件格式错误"));
          } else {
            callback();
          }
        } else {
          callback();
        }
      };
      return {
        isUserKnow_or_ExamAgreement_or_Exam: 'isUserKnow',
        selectedOptions: [], //选择后的省市区对象数组
        areaOptions: areaData, //省市区三级联动
        currentExamId: '',
        rules: {
          province: [
            {required: true, validator: province_rule, trigger: "change"},
          ],
          name: [{required: true, message: "请输入用户名", trigger: "blur"}],
          email: [{required: true, message: "请输入电子邮箱", trigger: "blur"}],
          last_py: [{required: true, validator: last_py_rule, trigger: "blur"}],
          first_py: [
            {required: true, validator: first_py_rule, trigger: "blur"},
          ],
          card_type: [
            {required: true, message: "请选择证件类型", trigger: "change"},
          ],
          cert: [
            {required: true, message: "请选择相关资质证书", trigger: "change"},
          ],
          card_id: [
            {required: true, message: "请输入证件号码", trigger: "blur"},
          ],
          birthday: [
            {
              required: true,
              message: "请输入出生年月",
              trigger: "blur",
            },
          ],
          ind_type: [
            {required: true, message: "请选择行业类型", trigger: "blur"},
          ],
          com_type: [
            {required: true, message: "请选择单位类型", trigger: "blur"},
          ],
          address: [
            {
              required: true,
              message: "请输入家庭住址",
              trigger: "blur",
            },
          ],
          org_code: [
            {required: true, message: "请输入报考机构代码", trigger: "blur"},
          ],
          school: [
            {required: true, message: "请输入学校名称", trigger: "blur"},
          ],
          grad_time: [
            {required: true, message: "请填写毕业年份", trigger: "change"},
          ],
          hig_edu: [
            {required: true, message: "请填写最高学历", trigger: "blur"},
          ],
          major: [{required: true, message: "请输入专业门类", trigger: "blur"}],
          com_name: [
            {required: true, message: "请输入单位名称", trigger: "blur"},
          ],
          work_duty: [
            {required: true, message: "请输入现有职务", trigger: "blur"},
          ],
          work_duty_en: [
            {required: true, validator: work_duty_en_rule, trigger: "blur"},
          ],
          work_title: [
            {required: true, message: "请输入现有职称", trigger: "blur"},
          ],
          work_age: [
            {required: true, message: "请填写从业年限", trigger: "change"},
          ],
          course: [
            {required: true, message: "请输入考试级别", trigger: "blur"},
          ],
          exam_date: [
            {required: true, message: "请填写考试时间", trigger: "change"},
          ],
          exam_city: [
            {required: true, message: "请填写考试形式", trigger: "change"},
          ],
          is_train: [
            {required: true, message: "请选择是否参加培训", trigger: "change"},
          ],
          photo: [{required: true, message: "请上传证件照", trigger: "blur"}],
          phone: [{validator: phoneRule, trigger: "blur"}],
          msg_code: [
            {required: true, message: "请输入手机验证码", trigger: "blur"},
          ],
        }, //报考表单验证
        examForm: {
          name: "", //姓名
          last_py: "", //姓拼音
          first_py: "", //名拼音
          card_type: 1, //证件类型
          card_id: "", //证件号码
          birthday: "", //出生日期
          address: "", //家庭住址
          province: "", //省份
          city: "", //城市
          region: "", //区/县
          org: {
            org_code: "", //机构代码
          },
          exam_org_code: "",
          school: "", //毕业学校
          grad_time: "", //毕业时间
          hig_edu: "", //最高学历
          major: "", //专业门类
          com_name: "", //单位名称
          work_duty: "", //现有职务
          work_duty_en: "", //现有职务英文
          work_title: "", //现有职称
          work_age: "0", //从业年限
          course: {
            id: "", //考试级别,
            name: "",
          },
          exam_date: "", //考试时间
          exam_city: "", //考试城市 (薪酬管理师)
          is_train: false, //是否参加培训 (薪酬管理师)
          photo: "", //上传证件照片
          sign: "", //电子签名
          phone: "", //手机号码
          msg_code: "", //手机验证码
          ind_type: null,
          com_type: null,
        }, //报考表单字段
        cardOptions: [
          {id: 1, name: "居民身份证"},
          {id: 2, name: "护照"},
          {id: 3, name: "港澳台胞身份证"},
        ], //证件类型字典
        examCityOptions: [], //考试城市
        examDateOptions: [], //考试时间
        work_dutyList: work_duty_list,
        certDisplayOptions: cert_list,
        ind_typeList: [
          {value: 1, name: '人力资源与人力资本服务'},
          {value: 2, name: '集成电路'},
          {value: 3, name: '人工智能'},
          {value: 4, name: '软件与平台'},
          {value: 5, name: '生命科学'},
          {value: 6, name: '生物医药'},
          {value: 7, name: '医疗保健'},
          {value: 8, name: '航空与航天'},
          {value: 9, name: '汽车'},
          {value: 10, name: '化工'},
          {value: 11, name: '工业产品和服务'},
          {value: 12, name: '消费品'},
          {value: 13, name: '能源和自然资源'},
          {value: 14, name: '金融'},
          {value: 15, name: '基础建设和建筑产品'},
          {value: 16, name: '机械和设备'},
          {value: 17, name: '媒体'},
          {value: 18, name: '金属和矿业'},
          {value: 19, name: '私募基金'},
          {value: 20, name: '零售'},
          {value: 21, name: '高科技'},
          {value: 22, name: '电信'},
          {value: 23, name: '公用事业'},
          {value: 24, name: '教育'},
          {value: 25, name: '文化'},
          {value: 26, name: '其他'},
          {value: 27, name: '无'}
        ],
        com_typeList: [
          {name: "事业单位", value: 1},
          {name: "人力资源服务机构", value: 2},
          {name: "会计（税务,律师）事务所", value: 3},
          {name: "其他中介机构", value: 4},
          {name: "金融机构（银行,证券,保险,信托,基金等）", value: 5},
          {name: "院校", value: 6},
          {name: "其他", value: 7},
        ],
        isDisabled: false,
        isRegister: false,
      }
    },
    created() {
      console.log('报考id', this.$route);
      this.getExamData();
    },
    methods: {
      showExamAgreement() {
        this.isUserKnow_or_ExamAgreement_or_Exam = 'ExamAgreement';
      },
      isExam() {
        this.isUserKnow_or_ExamAgreement_or_Exam = 'Exam';
        window.scrollTo(0, 0);
      },
      goBack() {
        this.$router.push({path: '/user'})
      },
      //获取考试时间
      examDataList(course_id) {
        exam_data_list(course_id).then(res => {
          console.log('考试时间', res);
          this.examCityOptions = res
          this.examDateOptions = res
          this.examForm.exam_city = res[0].exam_city;
          this.examForm.exam_date = res[0].id;
        })
      },
      //获取数据填充表单
      getExamData() {
        console.log('this.$route.params.exam_id', this.$route.params.exam_id);
        profile({pid: this.$route.params.exam_id}).then(res => {
          console.log('获取到的报考数据', res)
          let currentData = JSON.parse(JSON.stringify(res[0]));
          this.examForm = currentData;
          console.log('当前报考数据', this.examForm);
          this.examDataList(this.examForm.course.id);
          this.selectedOptions = textToCode([this.examForm.province, this.examForm.city, this.examForm.region])
          console.log('this.selectedOptions', this.selectedOptions)
        })
      },
      addressChangeExam(arr) {
        [this.examForm.province, this.examForm.city, this.examForm.region] = codeToText(arr);
      },
      codeHandle() {
        if (this.$refs.isShow) {
          this.$refs.captcha.handleCode();
          this.isDisabled = true;
        }
      },
      isRegisterFun() {
        window.open("/exam_register.html");
      },
      //合同签署
      userExtSign(params) {
        userExtSign(params).then(res => {
          window.location.href = res.sign_url
        })
      },
      //合同填充
      generateContract(params) {
        generate_contract(params).then(res => {
          console.log('合同签署', res);
          let params = {
            pid: this.examForm.id,
            return_url: return_url
          }
          this.userExtSign(params)
        })
      },
      //报考表单提交
      examReg() {
        this.$refs["examForm"].validate((valid) => {
          if (valid) {
            if (this.examForm.exam_org_code !== "") {
              console.log(this.examForm.exam_org_code);
              let orgCode = this.examForm.exam_org_code;
              getOrg({org_code: orgCode})
                      .then((examOrg) => {
                        console.log(examOrg.course[0].name.includes('薪税'))
                        if (examOrg.course && examOrg.course[0].name.includes('薪税')) {
                          if (this.examForm.is_train) {
                            if (this.isRegister) {
                              this.examForm.first_py = this.examForm.first_py.toLocaleUpperCase()
                              this.examForm.last_py = this.examForm.last_py.toLocaleUpperCase()
                              this.$confirm(`<div style="color: darkslategray"><p>请确认以下信息是否正确：</p><p>*姓：${this.examForm.last_py}</p><p>*名：${this.examForm.first_py}</p></div>`, '信息确认', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                dangerouslyUseHTMLString: true,
                              }).then(() => {
                                console.log('报考参数', this.examForm)
                                this.examForm.pid = this.examForm.id;
                                this.examForm.exam_org = this.examForm.exam_org_code;
                                this.examForm.exam_date_id = this.examForm.exam_date;

                                exam_reg(this.examForm).then(res => {
                                  console.log('报考数据', res);
                                  let province = this.examForm.province == null ? "" : this.examForm.province;
                                  let city = this.examForm.city == null ? "" : this.examForm.city;
                                  let detailTime = this.examDateOptions.filter((item) => item.id == this.examForm.exam_date_id)
                                  console.log('detailTime', detailTime)
                                  let region = this.examForm.region = null ? "" : this.examForm.region;
                                  let params = {
                                    pid: this.examForm.id,
                                    parameter_map: {
                                      major: this.examForm.major,
                                      org: this.examForm.org.org_name,
                                      exam_org: examOrg.org_name,
                                      course: this.examForm.course.name,
                                      ispass: (this.examForm.exam_record.length > 0 && this.examForm.exam_record[this.examForm.exam_record.length - 1].is_pass === false) || this.examForm.make_up_count > 0 ? '是' : '否',
                                      time_detail: detailTime[0].time_detail,
                                      exam_city: this.examForm.exam_city,
                                      user_name: this.examForm.name,
                                      name_en: this.examForm.first_py + ' / ' + this.examForm.last_py,
                                      card_type: this.examForm.card_type_display,
                                      card_id: this.examForm.card_id,
                                      gender: this.examForm.gender_display,
                                      birthday: this.examForm.birthday,
                                      hig_edu: this.examForm.hig_edu,
                                      grad_time: this.examForm.grad_time ? this.examForm.grad_time.split('-')[0] + '年' + this.examForm.grad_time.split('-')[1] + '月' : '',
                                      cert: this.examForm.cert,
                                      region: province + " " + city + " " + region,
                                      work_age: this.examForm.work_age + "年",
                                      com_name: this.examForm.com_name,
                                      email: this.examForm.email,
                                      work_duty_cn: this.examForm.work_duty.split('#')[0],
                                      work_duty_en: this.examForm.work_duty.split('#')[1],
                                      sign: "",
                                      current_date:
                                              new Date().getFullYear() +
                                              "年" +
                                              (new Date().getMonth() + 1) +
                                              "月" +
                                              new Date().getDate() +
                                              "日",
                                      ind_type: this.ind_typeList.filter(
                                              (element) => element.value == this.examForm.ind_type
                                      )[0].name,
                                      com_type: this.com_typeList.filter(
                                              (element) => element.value == this.examForm.com_type
                                      )[0].name,
                                      phone: this.examForm.phone
                                    },
                                  };
                                  console.log('合同签署参数', params)
                                  this.generateContract(params);
                                }).catch(err => {
                                  console.log('未知错误', err)
                                  this.$message({type: 'error', message: err.msg})
                                })
                              }).catch(err => {
                                this.$message({
                                  type: 'info',
                                  message: '已取消' + err
                                });
                              })
                            } else {
                              this.$message({
                                type: "warning",
                                message: "请您确定所提供的的个人信息及材料真实、合法、有效。",
                              });
                            }
                          } else {
                            this.$message({
                              type: "warning",
                              message: "您确认经培训已达规定的参考学时数。",
                            });
                          }
                        } else {
                          this.$message({type: "error", message: "对不起！该机构权限不可报考该科目"});
                        }
                      })
                      .catch((err) => {
                        console.log(err);
                        this.$message({type: "error", message: "报考机构不存在"});
                      });
            } else {
              this.$message({
                type: "warning",
                message: "机构代码不能为空",
              });
            }
          } else {
            this.$message({
              type: "warning",
              message: "请检查所有字段是否正确填写",
            });
            console.log("error submit!!");
            return false;
          }
        });
      },
    },
    components: {
      headerComponent,
      footerComponent,
      TencentCaptcha,
      userKnow,
      ExamAgreement
    }
  }
</script>

<style scoped>
  .exam {
    width: 1200px;
    margin: 0 auto;
  }
</style>
